<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>
    <!-- 启用条件下分区配置不可操作，禁用条件下课操作 -->
    <logistics-partition-classify-list ref="classifyForm" @ok="submitCallback" :disabled="disableSubmit"></logistics-partition-classify-list>
    <a-divider />
    <logistics-partition-country-list ref="countryForm" @ok="submitCallback" :disabled="disableSubmit"></logistics-partition-country-list>
    <a-divider />
    <logistics-partition-city-list ref="cityForm" @ok="submitCallback" :disabled="disableSubmit"></logistics-partition-city-list>
  </j-modal>
</template>

<script>

  import LogisticsPartitionClassifyList from '../LogisticsPartitionClassifyList'
  import LogisticsPartitionCountryList from '../LogisticsPartitionCountryList'
  import LogisticsPartitionCityList from '../LogisticsPartitionCityList.vue'
  export default {
    name: 'LogisticsPartitionClassifyModal',
    components: {
      LogisticsPartitionCountryList,
      LogisticsPartitionClassifyList,
      LogisticsPartitionCityList,
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        currentRecord: {}
      }
    },
    provide(){
      return {
        freshPartition: this.freshPartition
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.classifyForm.add();
        })
      },
      list (record) {
        this.currentRecord = record;
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.classifyForm.list(record);
          this.$refs.countryForm.list(record);
          this.$refs.cityForm.list(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$refs.classifyForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      freshPartition(){
        this.$refs.countryForm.list(this.currentRecord);
        this.$refs.cityForm.list(this.currentRecord);
      }
    }
  }
</script>